package com.ess.user.service.sys;

import com.ess.base.TableInfo;
import com.ess.base.service.impl.BaseServiceImpl;
import com.ess.constants.Constants;
import com.ess.user.mapper.SysDicMapper;
import com.ess.user.po.SysDic;
import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysDicService")
public class SysDicServiceImpl extends BaseServiceImpl<SysDic> implements SysDicService {

    @Autowired
    SysDicMapper sysDicMapper;

    /**
     * 查询除了当前字典表外的所有其他表
     *
     * @param dto
     * @return
     */
    @Override
    public PageInfo<TableInfo> queryTableName(TableInfo dto) {
        PageHelper.startPage(Constants.INT_ONE, Constants.INT_ZERO);
        List<TableInfo> list = sysDicMapper.queryTableName(dto);
        return new PageInfo<TableInfo>(list);
    }

    /**
     * 查询除了当前表的所有字段0.
     *
     * @param record
     * @return
     */
    @Override
    public PageInfo<TableInfo> queryTableColumn(TableInfo record) {
        PageHelper.startPage(Constants.INT_ONE, Constants.INT_ZERO);
        List<TableInfo> list = sysDicMapper.queryTableColumn(record);
        return new PageInfo<TableInfo>(list);
    }


    /**
     * 分页查询用户信息 可以设置排序，模糊查询
     *
     * @param page
     * @param rows
     * @param record
     * @return
     */
    @Override
    public PageInfo<SysDic> queryPageListByCondition(int page, int rows, SysDic record) {
        PageHelper.startPage(page, rows);
        Example example = new Example(SysDic.class);
        example.setOrderByClause(Constants.ORDER_UPDATE_DESC);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDeleted", Constants.STRING_ZERO);
        if (StringUtils.isNotBlank(record.getDicName())) {
            criteria.andLike("dicName", "%" + record.getDicName() + "%");
        }
        if (StringUtils.isNotBlank(record.getDicDes())) {
            criteria.andLike("dicDes", "%" + record.getDicDes() + "%");
        }
        if (StringUtils.isNotBlank(record.getDicType())) {
            criteria.andEqualTo("dicType", record.getDicType());
        }
        List<SysDic> list = super.mapper.selectByExample(example);
        return new PageInfo<SysDic>(list);
    }

}

